<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no" />
<base href="../" />

<!-- oktavia -->
<link rel="stylesheet" href="assets/searchstyle.css" type="text/css" />
<script src="search/jquery-1.9.1.min.js"></script>
<script src="search/oktavia-jquery-ui.js"></script>
<script src="search/oktavia-english-search.js"></script>
<!-- /oktavia -->

<link rel="stylesheet" href="assets/style.css" type="text/css" />

<title>Compress Directives - Configure - H2O - the optimized HTTP server</title>
</head>
<body>
<div id="body">
<div id="top">

<h1>
<a href="index.html">H2O</a>
</h1>
<p class="description">the optimized HTTP/1.x, HTTP/2, HTTP/3 server</p>

<!-- oktavia -->
<form id="searchform">
<input class="search" type="search" name="search" id="search" results="5" value="" placeholder="Search" />
<div id="searchresult_box">
<div id="close_search_box">&times;</div>
<div id="searchresult_summary"></div>
<div id="searchresult"></div>
<div id="searchresult_nav"></div>
<span class="pr">Powered by <a href="https://github.com/shibukawa/oktavia">Oktavia</a></span>
</div>
</form>
<!-- /oktavia -->

</div>

<table id="menu">
<tr>
<td><a href="index.html">Top</a></td>
<td><a href="install.html">Install</a></td>
<td class="selected"><a href="configure.html">Configure</a></td>
<td><a href="faq.html">FAQ</a></td>
<td><a href="http://blog.kazuhooku.com/search/label/H2O" target="_blank">Blog</a></td>
<td><a href="http://github.com/h2o/h2o/" target="_blank">Source</a></td>
</tr>
</table>

<div id="main">

<h2>
<a href="configure.html">Configure</a> &gt;
Compress Directives
</h2>


<p>
The compress handler performs on-the-fly compression - it compresses the contents of an HTTP response as it is being sent, if the client indicates itself to be capable of decompressing the response transparently with the use of <a href="https://tools.ietf.org/html/rfc7231#section-5.3.4"><code>Accept-Encoding</code></a> header</li>, and if the response is deemed compressible according to the following rules.
</p>
<p>
If <code>x-compress-hint</code> response header does not exist or the value is <code>auto</code>, then whether if the response is considered compressible depends on the <code>is_compressible</code> attribute assigned to the content type (see <a href="configure/file_directives.html#file.mime.addtypes"><code>file.mime.addtypes</code></a>).
If <code>x-compress-hint</code> response header exists and the value is <code>on</code>, the response is always considered to be compressible.
If the value of the response header is set to <code>off</code>, then the response never gets compressed.
</p>

<p>
The following are the  configuration directives recognized by the handler.
</p>

<ul>
<li><a href="configure/compress_directives.html#compress">
<code>compress</code>
</a></li>
<li><a href="configure/compress_directives.html#compress-minimum-size">
<code>compress-minimum-size</code>
</a></li>
<li><a href="configure/compress_directives.html#gzip">
<code>gzip</code>
</a></li>
</ul>


<div id="compress" class="directive-head">
<div class="directive-since">since v2.0</div>
<h3><a href="configure/compress_directives.html#compress"><code>"compress"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Enables on-the-fly compression of HTTP response.

</p>

<p>
If the argument is <code>ON</code>, both <a href="https://datatracker.ietf.org/doc/draft-alakuijala-brotli/">brotli</a> and <a href="https://tools.ietf.org/html/rfc1952">gzip</a> compression are enabled.
If the argument is <code>OFF</code>, on-the-fly compression is disabled.
If the argument is a sequence, the elements are the list of compression algorithms to be enabled.
If the argument is a mapping, each key specifies the compression algorithm to be enabled, and the values specify the quality of the algorithms.
</p>
<p>
When both brotli and gzip are enabled and if the client supports both, H2O is hard-coded to prefer brotli.
</p>
<div class="example">
<div class="caption">Example. Enabling on-the-fly compression</div>
<pre><code># enable all algorithms
compress: ON

# enable by name
compress: [ gzip, br ]

# enable gzip only
compress: [ gzip ]
</code></pre>
</div>


</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path, extension</dd>
<dt>Default:</dt>
<dd><code><pre>compress: OFF</pre></code>
<dt>See also:</dt>
<dd><a href="configure/file_directives.html#file.send-compressed"><code>file.send-compressed</code></a>, <a href="configure/file_directives.html#file.mime.addtypes"><code>file.mime.addtypes</code></a>
</dd>
</dl>

<div id="compress-minimum-size" class="directive-head">
<div class="directive-since">since v2.0</div>
<h3><a href="configure/compress_directives.html#compress-minimum-size"><code>"compress-minimum-size"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Defines the minimum size a files needs to have in order for H2O to compress the request.

</p>

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path, extension</dd>
<dt>Default:</dt>
<dd><code><pre>compress-minimum-size: 100</pre></code>
</dl>


<div id="gzip" class="directive-head">
<div class="directive-since">since v1.5</div>
<h3><a href="configure/compress_directives.html#gzip"><code>"gzip"</code></a></h3>
</div>

<dl class="directive-desc">
<dt>Description:</dt>
<dd>
<p>
Enables on-the-fly compression of HTTP response using gzip.

</p>

Equivalent to <code>compress: [ gzip ]</code>.

</dd>
<dt><a href="configure/syntax_and_structure.html#config_levels">Level</a>:</dt>
<dd>global, host, path, extension</dd>
<dt>Default:</dt>
<dd><code><pre>gzip: OFF</pre></code>
<dt>See also:</dt>
<dd><a href="configure/compress_directives.html#compress"><code>compress</code></a>
</dd>
</dl>






</div>
<div id="footer">
<p>
Copyright &copy; 2015-2025 <a href="http://dena.com/intl/">DeNA Co., Ltd.</a> et al.
</p>
</div>
</body>
</html>
